package com.hotdog.service;

import com.hotdog.feign.LoginFeignClient;
import com.hotdog.feign.PayFeignClients;
import com.hotdog.feign.SystemFeign;
import com.hotdog.pojo.Params;
import com.hotdog.pojo.PayInfo;
import com.hotdog.pojo.TokenDate;
import com.hotdog.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

/**
 * 支付宝回调具体实现
 *
 * @author 郭鲁政
 */
@Slf4j
@Service
public class ReturnPayUserServiceImpl implements ReturnPayUserService {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private PayFeignClients payFeignClients;
@Autowired
private LoginFeignClient loginFeignClient;
@Autowired
private SystemFeign systemFeign;
    @Override
    public void returnInfo() {
        if (PayInfo.orderId != null && PayInfo.money != null) {

            log.error(PayInfo.orderId);
            log.error(PayInfo.money);
            String name = SecurityContextHolder.getContext().getAuthentication().getName();
            //todo 远程调用数据库查询密码生成新的TOKEN
            System.out.println(name);
            User user = systemFeign.selectUserByUsername(name);
            System.out.println(user);
            Params params = new Params().setUsername(name).setPassword(user.getPassword());
            TokenDate token = loginFeignClient.getToken(params);
            System.out.println(token);
            payFeignClients.returnInfol(PayInfo.money, PayInfo.orderId);
        }

    }
}
